package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"manage/managerpc/internal/svc"
	"manage/managerpc/managerpc"
	"manage/models/mysql"
)

type LeaveListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLeaveListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LeaveListLogic {
	return &LeaveListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 留言列表
func (l *LeaveListLogic) LeaveList(in *managerpc.LeaveListRequest) (*managerpc.LeaveListResponse, error) {
	// todo: add your logic here and delete this line
	var user []mysql.Leave
	mysql.DB.Where("user_id", in.UserId).Find(&user)
	var Act []*managerpc.LeaveLists
	for _, n := range user {
		list := managerpc.LeaveLists{
			UserId:     int64(n.UserId),
			ActivityId: int64(n.ActivityId),
			Context:    n.Context,
			Id:         int64(n.ID),
		}
		Act = append(Act, &list)
	}
	return &managerpc.LeaveListResponse{
		List: Act,
	}, nil
}
